package com.mo2323.merchant.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mo2323.common.VO;
import com.mo2323.common.util.AjaxObject;
import com.mo2323.service.merchant.IBusinessAnalysis;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 高岐
 * @date 2019-01-23.
 */
@Controller
@RequestMapping("/business")
public class BusinessAnalysisController extends BaseController {
    @Reference
    private IBusinessAnalysis businessAnalysis;

    @RequestMapping(value = "/getBusinessStatData", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public AjaxObject getBusinessStatData(@RequestParam int vid,
                                          @RequestParam(value = "dateOption", defaultValue = "0", required = false) int dateOption) {
        try {
            VO vo = businessAnalysis.getBusinessSummaryData(vid, dateOption);
            return AjaxObject.ok().put("data", vo.toHashMap(true));
        } catch (Exception e) {
            logger.error("getBusinessStatData Exception：", e);
            return AjaxObject.error("getBusinessStatData Exception：" + e.getMessage());
        }
    }

    @RequestMapping(value = "/getBusinessAnalysisData", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public AjaxObject getBusinessAnalysisData(@RequestParam int vid) {
        try {
            VO vo = businessAnalysis.getBusinessAnalysisData(vid);
            return AjaxObject.ok().put("data", vo.toHashMap(true));
        } catch (Exception e) {
            logger.error("getBusinessStatData Exception：", e);
            return AjaxObject.error("getBusinessStatData Exception：" + e.getMessage());
        }
    }

    @RequestMapping(value = "/getBusinessAnalysisTrafficData", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public AjaxObject getBusinessAnalysisTrafficData(@RequestParam int vid) {
        try {
            VO vo = businessAnalysis.getBusinessAnalysisTrafficData(vid);
            return AjaxObject.ok().put("data", vo.toHashMap(true));
        } catch (Exception e) {
            logger.error("getBusinessStatData Exception：", e);
            return AjaxObject.error("getBusinessStatData Exception：" + e.getMessage());
        }
    }


    @RequestMapping(value = "/getBusinessAnalysisTradeData", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public AjaxObject getBusinessAnalysisTradeData(@RequestParam int vid) {
        try {
            VO retVO = businessAnalysis.getBusinessAnalysisTradeData(vid);
            return AjaxObject.ok().put("data", retVO.toHashMap(true));
        } catch (Exception e) {
            logger.error("getBusinessAnalysisTradeData Exception：", e);
            return AjaxObject.error("getBusinessAnalysisTradeData Exception：" + e.getMessage());
        }
    }
}
